/** 
 快速幂算法
**/
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;

ll binaryPow(ll a, ll b, ll m){
	ll ans = 1;
    a = a % m;
	while(b > 0){
		if(b & 1){
			ans = ans * a % m;
		}
		a = a * a % m;
		b >>= 1; 
	} 
	return ans;
}

int main()
{
    ll a, k, mode;
    cin >> a >> k >> mode;
    cout << binaryPow(a, k, mode) << endl;
    return 0;
}